package com.djl.sqtg.controller;

import com.djl.sqtg.entity.Category;
import com.djl.sqtg.entity.Goods;
import com.djl.sqtg.service.ICatecoryService;
import com.djl.sqtg.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("category")
public class CatecoryController extends BaseController{
    @Autowired
    private ICatecoryService catecoryService;

    @GetMapping({"getAllCategory"})
    public JsonResult<List> getAllCategory(){
        List<Category> categories=catecoryService.getAllCategory();
        List<Goods> goods = catecoryService.getCategoryGoodsById(1);
        List data = new ArrayList<>();
        data.add(categories);
        data.add(goods);
        System.out.println(data);
        return new JsonResult<List>(OK,data);
    }

    @GetMapping({"{gcid}/getCategoryGoodsById"})
    public JsonResult<List<Goods>> getCategoryGoodsById(@PathVariable("gcid") Integer gcid){
        List<Goods> data=catecoryService.getCategoryGoodsById(gcid);
        System.out.println(data);
        return new JsonResult<List<Goods>>(OK,data);
    }
}
